#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import re

def ereg(regex,string):
    try:
        r = re.compile(regex)
        m = r.match(string)
        if m is None:
            return None
        else:
            return m.groups()
    except: pass
    
def ereg_replace(regex,tostr,string):
        ris = re.findall(regex,string)
        keys = []
        for r in ris:
            if r not in keys:
                keys.append(r)
                string = string.replace(r,tostr)
                
        return string
